// ex8_8_2.cpp
#include <iostream>
#include <cstring>
struct CandyBar
{
    char brand[40];
    double weight;
    int calori;
};

void set_candybar(CandyBar &candybar, const char *brand = "Millennium Munch", double weight = 2.85, int calori = 350);
void display(const CandyBar &);

int main(void)
{
    CandyBar anncandy1, bencandy2;
    set_candybar(anncandy1);
    set_candybar(bencandy2, "Lemon Munch", 3.52, 360);
    display(anncandy1);
    display(bencandy2);

    return 0;
}

void set_candybar(CandyBar &candybar, const char *brand, double weight, int calori)
{
    char *ptr = candybar.brand;
    strncpy(ptr, brand, strlen(brand));
    
    ptr[strlen(brand)] = '\0';
    
    candybar.weight = weight;
    candybar.calori = calori;
}

void display(const CandyBar &c)
{
    std::cout << c.brand << " "
        << c.weight << " " 
        << c.calori << "\n";
}